Skip to content

[router] add ut for worker and errors#8170

Merged
zhyncs merged 1 commit intomainfrom
slin/ut-1
Jul 19, 2025
Merged

[router] add ut for worker and errors#8170
zhyncs merged 1 commit intomainfrom
slin/ut-1

Conversation

@slin1237
Copy link
Copy Markdown
Collaborator

Motivation

The sgl-router codebase currently lacks comprehensive unit tests, particularly for core modules like error handling and worker
management. According to the test coverage analysis, these modules had no unit tests, which poses risks for maintainability and
reliability. This PR addresses this gap by adding comprehensive unit tests for the core::error and core::worker modules,
improving code quality and developer confidence.

Modifications

This PR adds comprehensive unit tests for two critical modules in the sgl-router:

1. Error Handling Tests (src/core/error.rs)

  • Added 13 unit tests covering all error variants and display formatting
  • Tests include:
    • Display formatting for all 5 WorkerError variants
    • std::error::Error trait implementation verification
    • Send + Sync trait verification
    • WorkerResult type alias testing
    • Edge cases: empty URLs, special characters, very long messages
    • Error conversion from reqwest::Error

2. Worker Management Tests (src/core/worker.rs)

  • Added 34 comprehensive unit tests covering worker lifecycle and operations
  • Tests include:
    • WorkerType display and equality (3 tests)
    • HealthConfig default and custom configurations (2 tests)
    • BasicWorker creation and configuration (3 tests)
    • Worker trait implementation (8 tests)
    • Concurrent operations with thread safety verification (3 tests)
    • WorkerFactory for creating different worker types (4 tests)
    • WorkerCollection trait operations (4 tests)
    • WorkerLoadGuard RAII pattern with panic safety (3 tests)
    • Async health checker operations (3 tests)
    • Performance benchmarks (1 test - validates >1M ops/sec for atomic operations)

Test Approach

  • Tests are implemented in #[cfg(test)] modules within the source files following Rust idioms
  • All tests are passing (47 new tests total)
  • Thread safety verified through concurrent operation tests
  • Performance requirements validated (atomic operations exceed 1M ops/sec)

Checklist

  • Format your code according to the Code Formatting with
    Pre-Commit
    .
  • Add unit tests as outlined in the Running Unit
    Tests
    .
  • Update documentation / docstrings / example tutorials as needed, according to Writing
    Documentation
    .
  • Provide throughput / latency benchmark results and accuracy evaluation results as needed, according to Benchmark and
    Profiling
    and Accuracy
    Results
    .
    • Load counter performance test results: 79,711,184 ops/sec (requirement: >1M ops/sec ✓)
  • For reviewers: If you haven't made any contributions to this PR and are only assisting with merging the main branch, please
    remove yourself as a co-author when merging the PR.
  • Please feel free to join our Slack channel at https://slack.sglang.ai to discuss your PR.

Test Results

# All 47 new tests passing
cargo test core::error::tests core::worker::tests --lib
...
test result: ok. 47 passed; 0 failed; 0 ignored; 0 measured

Performance benchmark result from test_load_counter_performance:
Load counter operations per second: 79711184

This PR significantly improves test coverage for critical router components, ensuring reliability and maintainability of the error
handling and worker management systems.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants